<template>
  <div style="display: flex;justify-content: center;align-items: center;height: 60%">
    <el-form label-width="120px" label-position="right" style="width: 500px">
      <el-divider>关键性配置</el-divider>
      <el-form-item label="accessKey">
        <el-input v-model="entityInfo.accessKey"></el-input>
      </el-form-item>
      <el-form-item label="accessSecret">
        <el-input v-model="entityInfo.accessSecret"></el-input>
      </el-form-item>
      <el-form-item label="storeUrl">
        <el-input v-model="entityInfo.storeUrl"></el-input>
      </el-form-item>
      <el-form-item style="width: 100%;text-align: center">
        <el-button icon="el-icon-circle-check" type="success" @click="saveData(entityInfo)">{{ entityInfo.accessKey ? '更新' : '保存' }}</el-button>
      </el-form-item>
      <el-divider>管理员验证</el-divider>
      <el-form-item label="用户">
        <el-input v-model="entityInfo.user"></el-input>
      </el-form-item>
      <el-form-item label="密码">
        <el-input v-model="entityInfo.pass" show-password></el-input>
      </el-form-item>
      <el-form-item style="width: 100%;text-align: center">
        <el-button icon="el-icon-circle-check" type="danger" @click="login(entityInfo)">验证</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import IdeaTable from "@/mixins/IdeaTable";

export default {
  name: "ClientInfo",
  mixins: [IdeaTable],
  watch: {
    loading() {
      if (!this.loading && this.dataSource.length > 0) {
        this.$Util.copyAttr(this.dataSource[0], this.entityInfo,null,this)
      } else {
        this.$Util.cleanObj(this, this.entityInfo)
      }
    }
  },
  data(){
    return {
      adminUser: 'labTicl4',
      adminPass: 'labTicl4@2023'
    }
  },
  created() {
    this.queryUrl = '/systemConf/queryPage'
    this.saveUrl = '/systemConf/save'
    this.rowKey = 'confId'
    this.pageInfo.pageSize = 2
    this.loadSource()
  },
  methods: {
    initEntity() {
      if (this.dataSource.length === 0) {
        this.entityInfo = {}
      } else {
        this.$Util.copyAttr(this.dataSource[0], this.entityInfo,null,this)
      }
    },
    login() {
      if (this.entityInfo.user === this.adminUser && this.entityInfo.pass === this.adminPass) {
        this.$AuthStorage.setAccessToken('lab-token', 600)
      } else {
        this.$AuthStorage.clear();
      }
    }
  }
}
</script>

<style scoped>

</style>
